#pragma once
#undef UNICODE
#define WIN32_LEAN_AND_MEAN

#include <windows.h>
#include <winsock2.h>
#include <ws2tcpip.h>
#include <stdlib.h>
#include <stdio.h>

// Need to link with Ws2_32.lib
#pragma comment (lib, "Ws2_32.lib")
// #pragma comment (lib, "Mswsock.lib")

#define DEFAULT_BUFLEN 512
#define DEFAULT_PORT "27015"

#include "Definitions.h"

class Command;
class Controller;

class ServerComm
{
public:
	ServerComm();
	~ServerComm();
public:
	void Init(Controller* c);
	void RunCommCheck(Command* Cmd);
private:
	void CheckForNewClient();
	bool CheckForData();
	void ProcessData(Command* Cmd);
private:
	int numClients, CurrentClient;
	Controller* control;
private:
    WSADATA wsaData;
    SOCKET ListenSocket, ClientSocket[NUM_MAX_CLIENTS];
	struct addrinfo *result, hints;
    int iResult, recvbuflen, iSendResult;
    char recvbuf[DEFAULT_BUFLEN];
	u_long NonBlocking;
};